package com.speaktoitcookbook.dao.proxy;

import java.sql.Connection;
import java.util.List;

import com.speaktoitcookbook.bean.Collection;
import com.speaktoitcookbook.bean.UserInfo;
import com.speaktoitcookbook.dao.ICollectionDao;
import com.speaktoitcookbook.dao.impl.CollectionDaoImpl;
import com.speaktoitcookbook.db.Database;

/**
 * 收藏信息数据操作代理类
 * 
 * @author 赛艳志 杨强
 * 
 */
public class CollectionDaoProxy implements ICollectionDao {
    private Connection conn;
    private ICollectionDao dao;

    public CollectionDaoProxy() {
        this.conn = Database.getInstance().getConnection();
        this.dao = new CollectionDaoImpl(conn);
    }

    @Override
    public boolean doCreate(Collection collection) {
        boolean result = false;
        if (null != collection) {
            result = dao.doCreate(collection);
        }
        Database.close(conn);
        return result;
    }

    @Override
    public boolean doDelete(Collection collection) {
        boolean result = false;
        if (null != collection) {
            result = dao.doDelete(collection);
        }
        Database.close(conn);
        return result;
    }

    @Override
    public boolean doDelete(String userID, long cookbookID) {
        boolean result = false;
        if ((null != userID) && (!userID.isEmpty()) && (cookbookID > 0)) {
            result = dao.doDelete(userID, cookbookID);
        }
        Database.close(conn);
        return result;
    }

    @Override
    public boolean doUpdate(Collection collection) {
        boolean result = false;
        if (null != collection) {
            result = dao.doUpdate(collection);
        }
        Database.close(conn);
        return result;
    }

    @Override
    public List<Collection> getCollection(String userID) {
        List<Collection> result = null;
        if ((null != userID) && (!userID.isEmpty())) {
            result = dao.getCollection(userID);
        }
        Database.close(conn);
        return result;
    }

    @Override
    public List<UserInfo> getCollection(long cookbookID) {
        List<UserInfo> result = null;
        if (cookbookID > 0) {
            result = dao.getCollection(cookbookID);
        }
        Database.close(conn);
        return result;
    }
}
